package com.scalar.chiptrack.externalusers.forms;

import com.scalar.chiptrack.ChipTrackActionForm;
import com.scalar.chiptrack.commons.SessionKeys;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import java.util.HashMap;

public class ExternalUserLoginForm extends ChipTrackActionForm {

    private String userId = null;
    private String password = null;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public ActionErrors validate (ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {

        HashMap errors = new HashMap();

        if ((userId == null) || (userId.trim().length() == 0)) {
            errors.put ("User Name", "User ID required");
        }

        if ((password == null) || (password.length() == 0)) {
            errors.put ("Password", "Password required");
        }

        request.setAttribute(SessionKeys.ERROR_MESSAGES, errors);
        return null;
    }
}